package com.example.bowlingscorebook;

import android.content.Context;
import android.view.View;
import android.os.Bundle;
import android.util.AttributeSet;
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
//import android.graphics.drawable.ShapeDrawable;
//import android.graphics.drawable.shapes.RectShape;
import android.util.Log;

public class ScoreView extends View {

	public ScoreView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		setFocusable(false);
		setBackgroundColor(Color.WHITE);
	}

	public ScoreView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		setFocusable(false);
		setBackgroundColor(Color.WHITE);
	}
	
	public ScoreView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		setFocusable(false);
		setBackgroundColor(Color.WHITE);
	}

    @Override
	protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec){
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		int width = MeasureSpec.getSize(widthMeasureSpec);
		int height = width / 10;
		setMeasuredDimension(width, height);
	}

	@Override
    protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

/*
ShapeDrawable rect = new ShapeDrawable(new RectShape());
rect.getPaint().setColor(Color.BLUE);
rect.setBounds(10, 10, 150, 30);
rect.draw(canvas);
 */

		Paint paint = new Paint();

		paint.setAntiAlias(true);

		int l = 10;
		int t = 10;
		int w = getWidth() - 20;
		int h = getHeight() - 20;

		paint.setStyle(Paint.Style.STROKE);
		paint.setColor(Color.BLACK);

		paint.setStrokeWidth(2);
		canvas.drawRect(l, t, l+w, t+h, paint);

		paint.setStrokeWidth(1);
		canvas.drawLine(l, t+h/2, l+w, t+h/2, paint);

		for (int i=1; i<10; ++i) {
			int x = l + w / 10 * i;
			paint.setStrokeWidth(2);
			canvas.drawLine(x, t, x, t+h, paint);

			x -= w / 20;
			paint.setStrokeWidth(1);
			canvas.drawLine(x, t, x, t+h/2, paint);
		}
		for (int i=1; i<3; ++i) {
			int x = l + w / 10 * 9 + i * w / 30;
			canvas.drawLine(x, t, x, t+h/2, paint);
		}
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		super.onSizeChanged(w, h, oldw, oldh);
		Log.v("size changed", "w=" + w + ", h~" + h);
	}
}
